package com.freda.oa.flow.run.service.impl;

import com.freda.oa.flow.run.model.itf.FlowHisTaskmodelItf;
import com.freda.oa.flow.run.model.itf.FlowInstanceModelItf;
import com.freda.oa.flow.run.model.itf.FlowPartModelItf;
import com.freda.oa.flow.run.model.itf.FlowTaskModelItf;
import com.freda.oa.flow.run.service.itf.FlowRunServiceItf;
import com.freda.oa.flow.run.vo.FlowRunInfoVo;

/**
 * 流程业务逻辑层
 * 
 * @author Rally
 * 
 */
public class FlowRunServiceImpl extends FlowBaseServiceImpl implements FlowRunServiceItf {
	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.service.impl.FlowRunServiceItf#nodeToEnd(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int nodeToEnd(FlowRunInfoVo runInfo) 
	{

		super.instance.editInstance(runInfo);

		hisTask.editHisTask(runInfo);

		return 1;
	}

	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.service.impl.FlowRunServiceItf#silmpleToNext(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int silmpleToNext(FlowRunInfoVo runInfo) 
	{
		this.nodeToEnd(runInfo);

		if (runInfo.getAssigneeId().indexOf(",") != -1) 
		{
			String assIdStr = runInfo.getAssigneeId();
			String[] assId = assIdStr.split(",");

			runInfo.setAssigneeId("-1");

			hisTask.addHisTask(runInfo);

			task.editTask(runInfo);

			for (int i = 0; i < assId.length; i++) 
			{
				runInfo.setAssigneeId(assId[i]);
				part.addPart(runInfo);
			}
		} 
		else 
		{
			hisTask.addHisTask(runInfo);
			
			task.editTask(runInfo);
		}

		return 1;
	}

	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.service.impl.FlowRunServiceItf#foreachToNext(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int foreachToNext(FlowRunInfoVo runInfo) 
	{
		this.nodeToEnd(runInfo);

		return 0;
	}

	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.service.impl.FlowRunServiceItf#joinToNext(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int joinToNext(FlowRunInfoVo runInfo) 
	{
		this.nodeToEnd(runInfo);

		return 0;
	}

	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.service.impl.FlowRunServiceItf#stateToNext(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int stateToNext(FlowRunInfoVo runInfo) 
	{
		this.nodeToEnd(runInfo);

		return 0;
	}

	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.service.impl.FlowRunServiceItf#doPerusal(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int doPerusal(FlowRunInfoVo runInfo) 
	{
		return 0;
	}

	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.service.impl.FlowRunServiceItf#perusalCompleted(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int perusalCompleted(FlowRunInfoVo runInfo) 
	{
		return 0;
	}

	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.service.impl.FlowRunServiceItf#flowToEnd(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int flowToEnd(FlowRunInfoVo runInfo) 
	{
		this.nodeToEnd(runInfo);

		return 0;
	}

	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.service.impl.FlowRunServiceItf#lockAssignee(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int lockAssignee(FlowRunInfoVo runInfo) 
	{
		task.lockAssignee(runInfo);

		hisTask.lockAssignee(runInfo);

		return 0;
	}

	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.service.impl.FlowRunServiceItf#unLockAssignee(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int unLockAssignee(FlowRunInfoVo runInfo) 
	{
		task.unLockAssignee(runInfo);

		hisTask.unLockAssignee(runInfo);

		return 0;
	}

	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.service.impl.FlowRunServiceItf#getFlowInfo(com.freda.oa.flow.run.vo.FlowRunInfoVo, java.lang.String)
	 */
	@Override
	public FlowRunInfoVo getFlowInfo(FlowRunInfoVo runInfo, String type) 
	{
		return null;
	}

	/* (non-Javadoc)
	 * @see com.freda.oa.flow.run.service.impl.FlowRunServiceItf#flowToStart(com.freda.oa.flow.run.vo.FlowRunInfoVo)
	 */
	@Override
	public int flowToStart(FlowRunInfoVo runInfo) {

		return 0;
	}
}
